package com.kuangjia.student_ems.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;

import java.time.LocalDateTime;

@Entity
@Table(name = "leaves")
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("leaves")
public class Leave {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableId(value = "id", type = com.baomidou.mybatisplus.annotation.IdType.AUTO)
    private Long id;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = false)
    @TableField(exist = false)
    private User user;
    
    @TableField("user_id")
    @Column(name = "user_id", insertable = false, updatable = false)
    private Long userId;
    
    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private LeaveType type;
    
    @Column(nullable = false)
    private LocalDateTime startTime;
    
    @Column(nullable = false)
    private LocalDateTime endTime;
    
    private String reason;
    
    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private LeaveStatus status;
    
    private String rejectReason;
    
    @Column(name = "approve_reason")
    private String approveReason;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "approver_id")
    @TableField(exist = false)
    private User approver;
    
    @TableField("approver_id")
    @Column(name = "approver_id", insertable = false, updatable = false)
    private Long approverId;
    
    private LocalDateTime approveTime;
    
    @CreationTimestamp
    private LocalDateTime createTime;
    
    @UpdateTimestamp
    private LocalDateTime updateTime;
    
    public enum LeaveType {
        ANNUAL,       // 年假
        SICK,         // 病假
        PERSONAL,     // 事假
        MARRIAGE,     // 婚假
        MATERNITY,    // 产假
        PATERNITY,    // 陪产假
        BEREAVEMENT,  // 丧假
        OTHER         // 其他
    }
    
    public enum LeaveStatus {
        PENDING,      // 待审批
        APPROVED,     // 已批准
        REJECTED,     // 已拒绝
        CANCELLED     // 已取消
    }
} 